package com.istock.union.config;

import java.util.ArrayList;
import java.util.List;

import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.istock.base.logtrace.filter.TraceNoFilter;
import com.istock.base.web.servlet.HealthCheckServlet;
import com.istock.union.user.filter.SSOFilter;

@Configuration
public class FilterConfig {

	@Bean
	public FilterRegistrationBean logFilterRegistration()
	{
		FilterRegistrationBean registrationBean = new FilterRegistrationBean();
		TraceNoFilter filter = new TraceNoFilter();
		registrationBean.setFilter(filter);
		List<String> urlPatterns = new ArrayList<String>();
	    urlPatterns.add("/*");
	    registrationBean.setUrlPatterns(urlPatterns);
	    registrationBean.setOrder(2);
		return registrationBean;
	}
	
	@Bean
	public FilterRegistrationBean ssoFilterRegistration(SSOFilter filter)
	{
		FilterRegistrationBean registrationBean = new FilterRegistrationBean();
		registrationBean.setFilter(filter);
		List<String> urlPatterns = new ArrayList<String>();
	    urlPatterns.add("/*");
	    registrationBean.setUrlPatterns(urlPatterns);
	    registrationBean.setOrder(3);
		return registrationBean;
	}
	
	@Bean
	public ServletRegistrationBean healthCheckRegistration(){
		ServletRegistrationBean registrationBean = new ServletRegistrationBean();
		registrationBean.setServlet(new HealthCheckServlet());
		registrationBean.addUrlMappings("/_health_check.ttt");
		return registrationBean;
	}
}
